package net.jeanhwea.util;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class HtmlTag {
	private Map<String, String> attri = new HashMap<String, String>();
	private String name = "";
	
	private boolean ending;
	
	public void clear() {
		this.attri.clear();
		this.name = "";
		this.ending = false;
	}
	
	public String getAttributeValue(String name) {
		return this.attri.get(name.toLowerCase());
	}	
	public void setAttribute(String name, String value) {
		this.attri.put(name.toLowerCase(), value);
	}
	
	public String getName(){
		return name;
	}
	public void setName(String name){
		this.name = name;
	}
	
	public boolean isEnding(){
		return this.ending;
	}
	public void setEnding(boolean ending) {
		this.ending = ending;
	}

	@Override
	public String toString(){
		StringBuilder buffer = new StringBuilder("<");
		buffer.append(this.name);
		
		Set<String> set = this.attri.keySet();
		for (String key : set) {
			String value = this.attri.get(key);
			buffer.append(' ');
			if(value == null){
				buffer.append("\"");
				buffer.append(key);
				buffer.append("\"");
			}else {
				buffer.append(key);
				buffer.append("=\"");
				buffer.append(value);
				buffer.append("\"");
			}
		}
		
		if(this.ending){
			buffer.append('/');
		}
		buffer.append(">");
		return this.toString();
	}
	
	
}
